package com.test.dao.impl;

import com.test.dao.IBuildDao;
import com.test.model.Build;
import com.test.model.BuildMeter;
import com.test.model.BuildValve;
import com.test.model.House;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by ZZF on 2017/7/18.
 */
@Repository
public class BuildDaoImpl  extends BaseDaoImpl<Build> implements IBuildDao {
    @Override
    public List<BuildValve> findBuildValve(int buildId) {

        String Sql="SELECT b.*  FROM g_build a INNER JOIN rcc_e_buildvalve b on " +
                "a.uniqueId=b.buildId WHERE a.uniqueId="+buildId;
        Query query = getSession().createSQLQuery(Sql).addEntity(BuildValve.class);

        return query.list();
    }

    @Override
    public  List<BuildMeter> findBuildMeter(int buildId) {
        String Sql="SELECT b.*  FROM g_build a INNER JOIN rcc_e_buildmeter b on " +
                "a.uniqueId=b.buildId WHERE a.uniqueId="+buildId;
        Query query = getSession().createSQLQuery(Sql).addEntity(BuildMeter.class);

        return query.list();
    }

    @Override
    public List<House> findHouse(int buildId) {

        String Sql="SELECT c.* FROM g_build a INNER JOIN g_unit b ON b.buildId=a.uniqueId INNER JOIN g_house c " +
                "ON c.unitId=b.uniqueId WHERE a.uniqueId="+buildId;

        Query query = getSession().createSQLQuery(Sql).addEntity(House.class);

        return query.list();
    }
}
